#ifndef _CCONFIGFILE_H_
#define _CCONFIGFILE_H_

/**

This is the Config File class

*/
class CConfigFile
{
public:
	typedef union
	{
		double asNumber;
		char asKey;
		char *asString;
	}UValue;
private:
	typedef struct
	{
		char *name;
		UValue val_current;
		UValue val_default;
		int flags;
		int type;
	}TConfigEntry;

	int m_numValues;
	int m_maxValues;
	TConfigEntry *m_entries;
	char *m_lastFile;

	int findKey(const char *key);
	void releaseData();
	int createKey(const char* name, bool verify);
public:
	enum {FLAG_NONE=0x00, FLAG_HIDDEN = 0x01};
	enum {TYPE_NUMBER=1, TYPE_STRING, TYPE_KEY};
	/**
	Creates the configuration file
	*/
	CConfigFile();

	/**
	Destroys the configuration file
	*/
	~CConfigFile();

	/**
	Reads and parses a <i>config file< /i>.
	\param file The file name
	*/
	int readConfig(const char *file);
	int writeConfig(const char *file);
	UValue getValue(const char *name);
	void setValue_asNumber(const char *name, double value, int flags);
	void setValue_asString(const char *name, const char *value, int flags);
	void setValue_asKey(const char *name, char value, int flags);
};

#endif //_CCONFIGFILE_H_